package Pool;

import java.util.concurrent.*;
public class demo1 {
    public static void main(String[] args) {
        BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(10);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                4, 4, 1, TimeUnit.SECONDS, blockingQueue,Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy()
        );
        for (int i = 0; i < 10; i++) {
            final int id = i;
            //提交任务
            threadPoolExecutor.submit(new Runnable() {
                @Override
                public void run() {
                    String name = Thread.currentThread().getName();
                    System.out.println(name + "-" + id);//匿名内部类访问外部成员，变量捕获
                }
            });
        }
        threadPoolExecutor.shutdown();
    }
}
